package com.bcu.cn.onlineexamsystem.studentmanage.controller;

import com.bcu.cn.onlineexamsystem.studentmanage.service.StudentExamPdfService;
import com.bcu.cn.onlineexamsystem.user.entity.User;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student/exam/pdf")
public class StudentExamPdfController {

    @Autowired
    private StudentExamPdfService studentExamPdfService;

    @GetMapping("/export/{recordId}")
    public void exportExamDetailPdf(@PathVariable Long recordId, HttpSession session, HttpServletResponse response) {
        User user = (User) session.getAttribute("user");
        if (user == null || !"student".equals(user.getRole())) {
            throw new RuntimeException("未登录或无权限");
        }
        studentExamPdfService.exportExamDetailPdf(recordId, user.getUserId(), response);
    }
} 